<?php
/*------------------------------------------------------------------------
 * PluginWidget.class.php 
 *
 * 插件
 * 	
 * Created on 2015-12-16
 *
 * Author: hwc123 <hwc123@139.com>
 * 
 * Copyright (c) 2015 http://www.qingtajiao.com All rights reserved.
 * ------------------------------------------------------------------------
 */

namespace Admin\Widget;
use Think\Controller;
class PluginWidget extends Controller {
	/**
	 * 通用类别选择
	 * @param  [type]  $category_name   类别名称
	 * @param  string  $category_field  类别字段
	 * @param  string  $category_type   类别标识
	 * @param  integer $is_category_add 显示添加
	 */
	public function category_select($category_name, $category_field = 'category_id', $category_type = 'identity',$is_required = 1, $is_category_add = 1, $is_wrap_name = 1){
		$where['module']  = $category_type;
		$where['status']  = 1;
		$category_list = D('category')->where($where)->order('user_id,order_id,id desc')->select();

		if($category_list){
			foreach ($category_list as $rs) {
				$category_name_info[$rs['id']] = $rs['title'];
			}
		}

		$this->assign('is_required', $is_required);
		$this->assign('category_name', $category_name);
		$this->assign('category_field', $category_field);
		$this->assign('category_type', $category_type);
		$this->assign('category_list', $category_list);
		$this->assign('is_category_add', $is_category_add);
		$this->assign('is_wrap_name', $is_wrap_name);
		$this->assign('category_name_info', $category_name_info);
		$this->display('Category:common_select');
	}
	/**
	 * 通用类别选择
	 * @param  [type]  $category_name   类别名称
	 * @param  string  $category_field  类别字段
	 * @param  string  $category_type   类别标识
	 * @param  integer $is_category_add 显示添加
	 */
	public function tags_select($name = '标签', $field = 'tags_id', $join_id = '', $module = 'article'){
		$where['module']  = $module;
		$where['join_id'] = $join_id;
		$where['field']   = $field;
		$list = D('TagsJoin')->where($where)->select();
		foreach ($list as $rs) {
			$rs['content'] = D('Tags')->where(array('tags_id' => $rs['tags_id']))->getField('content');
			$new_list[] = $rs;
		}
		
		$this->assign('tags_name', $name);
		$this->assign('tags_field', $field);
		$this->assign('tags_list', $new_list);
		$this->assign('tags_module', $module);
		$this->display('Tags:tags_select');
	}
	/**
	 * 上传文件
	 * @param  string  $upload_field    上传字段
	 * @param  string  $upload_type     上传类型img图片 file文件
	 * @param  string  $upload_name     显示名称
	 * @param  string  $upload_desc     名称描述如100*100
	 * @param  integer $is_multi        是否上传多个文件，默认为单个
	 * @param  string  $upload_file_ext 后缀，如jpg,apk,zip,doc
	 * @param  integer $is_wrap_name    是否包含名称
	 * @param  string  $upload_value    上传字段值，多个用逗号分隔
	 */
	public function upload_file($upload_field = 'images_id', $upload_type = 'img', $upload_name = '', $upload_desc = '', $is_multi = 0, $upload_file_ext = '', $is_wrap_name = 1, $upload_value = '', $is_upload = 1){
		//默认配置
		$upload_field    = $upload_field ? $upload_field : 'images_id';//上传字段
		$upload_type     = $upload_type ? $upload_type : 'img';//文件类型
		$upload_name     = $upload_name ? $upload_name : ($upload_type == 'img' ? '图片' : '文件');//显示名称
		$upload_desc     = $upload_desc ? '(' . $upload_desc . ')' : '';
		$is_wrap_name    = $is_wrap_name == 1 ? 1 : 0;
		$upload_file_ext = $upload_file_ext ? $upload_file_ext : '';
		$is_multi        = $is_multi == 1 ? 1 : 0;
		$is_upload       = $is_upload == 1 ? 1 : 0;

		$this->assign('is_upload', $is_upload);
		$this->assign('is_multi', $is_multi);
		$this->assign('upload_list', $upload_list);
		$this->assign('upload_type', $upload_type);
		$this->assign('upload_name', $upload_name);
		$this->assign('upload_desc', $upload_desc);
		$this->assign('is_wrap_name', $is_wrap_name);
		$this->assign('upload_field', $upload_field);
		$this->assign('upload_value', $upload_value);
		$this->assign('upload_file_ext', $upload_file_ext);
		$this->display('File:common_upload');
	}
	public function area_select($show_name = '', $is_wrap_name = 1, $is_required = 1, $is_disabled = 0, $show_field = 'province_id,city_id', $province_id = 4, $city_id = 60, $area_id = 587){
		$province_where['type'] = 1;
		$province_list = D('Area')->where($province_where)->select();

		$show_field_arr   = explode(',', $show_field);
		$is_show_province = in_array('province_id', $show_field_arr);
		$is_show_city     = in_array('city_id', $show_field_arr);
		$is_show_area     = in_array('area_id', $show_field_arr);

		if($province_id && $is_show_city){
			$city_where['type'] = 2;
			$city_where['parentid'] = $province_id;
			$city_list = D('Area')->where($city_where)->select();
		}

		if($city_id && $is_show_area){
			$area_where['type'] = 3;
			$area_where['parentid'] = $city_id;
			$area_list = D('Area')->where($area_where)->select();
		}

		$this->assign('is_show_province', $is_show_province);
		$this->assign('is_show_city', $is_show_city);
		$this->assign('is_show_area', $is_show_area);
		$this->assign('city_id', $city_id);
		$this->assign('area_id', $area_id);
		$this->assign('show_name', $show_name);
		$this->assign('province_id', $province_id);
		$this->assign('province_list', $province_list);
		$this->assign('city_list', $city_list);
		$this->assign('area_list', $area_list);
		$this->assign('is_disabled', $is_disabled);
		$this->assign('is_required', $is_required);
		$this->assign('is_wrap_name', $is_wrap_name);
		$this->display('Area:area_select');
	}
	/**
	 * 选择用户
	 * @param  string  $show_name  显示名称
	 * @param  string  $user_field 字段名称
	 * @param  string  $user_type  类型all所有用户,lawyer律师用户，user普通用户
	 * @param  integer $is_mulit   是否选择多个
	 * @param  string  $user_value 值
	 */
	public function select_user($show_name = '用户', $user_field = 'user_id', $user_type = 'all', $is_mulit = 1, $user_value = ''){
		$this->assign('show_name', $show_name);
		$this->assign('user_field', $user_field);
		$this->assign('user_type', $user_type);
		$this->assign('is_mulit', $is_mulit);
		$this->assign('user_value', $user_value);

		$this->display('User:common_user_select');
	}
	public function select_admin_user($show_name = '用户', $user_field = 'user_id', $is_mulit = 1, $user_value = ''){
		$this->assign('show_name', $show_name);
		$this->assign('user_field', $user_field);
		$this->assign('is_mulit', $is_mulit);
		$this->assign('user_value', $user_value);

		$this->display('Admin:common_user_select');
	}
}



